<template>
  <div class="retail-products">
    <div class="page-header">
      <h1>零售商品管理</h1>
      <div class="header-actions">
        <div class="view-toggle">
          <label class="toggle-label">
            <input type="checkbox" v-model="groupByProduct" @change="toggleGroupView">
            <span class="toggle-text">按基础商品分组</span>
          </label>
        </div>
        <button class="btn-primary" @click="showCreateModal = true">
          <i class="fas fa-plus"></i>
          添加商品
        </button>
      </div>
    </div>

    <!-- 搜索和筛选 -->
    <div class="search-action-section">
      <div class="search-form">
        <div class="form-item">
          <label>商品名称</label>
          <input v-model="searchForm.productName" type="text" placeholder="请输入商品名称">
        </div>
        <div class="form-item">
          <label>商品编码</label>
          <input v-model="searchForm.productCode" type="text" placeholder="请输入商品编码">
        </div>
        <div class="form-item">
          <label>商品状态</label>
          <select v-model="searchForm.status">
            <option value="">全部</option>
            <option value="Active">启用</option>
            <option value="Inactive">禁用</option>
          </select>
        </div>
        <div class="form-item">
          <label>库存状态</label>
          <select v-model="searchForm.stockStatus">
            <option value="">全部</option>
            <option value="normal">正常</option>
            <option value="low">低库存</option>
            <option value="out">缺货</option>
          </select>
        </div>
        <div class="form-buttons">
          <button class="btn btn-primary" @click="searchProducts">
            <i class="fas fa-search"></i>
            搜索
          </button>
          <button class="btn btn-secondary" @click="resetSearch">
            <i class="fas fa-refresh"></i>
            重置
          </button>
        </div>
      </div>
    </div>

    <!-- 商品列表和分页 -->
    <div class="table-pagination-section">
      <div class="table-container">
      <table>
        <thead>
          <tr>
            <th>商品信息</th>
            <th>零售价格</th>
            <th>会员价格</th>
            <th>库存状态</th>
            <th>商品状态</th>
            <th>创建时间</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="product in displayProducts" :key="product.id">
            <td>
              <div class="product-info">
                <div class="product-image">
                  <img :src="product.productImage || product.image || '/default-product.png'" :alt="product.productName || product.name">
                </div>
                <div class="product-details">
                  <div class="product-name">
                    {{ product.productName || product.name || '未命名商品' }}
                    <span v-if="product.skuCode && product.skuCode !== '无SKU'" class="sku-variant">
                      ({{ product.skuCode }})
                    </span>
                  </div>
                  <div class="product-code">{{ product.productCode || product.code || '无编码' }}</div>
                  <div class="product-sku">{{ product.skuCode || '无SKU' }}</div>
                </div>
              </div>
            </td>
            <td>
              <span class="retail-price">¥{{ (product.retailPrice || 0).toFixed(2) }}</span>
            </td>
            <td>
              <span class="member-price">¥{{ (product.memberPrice || 0).toFixed(2) }}</span>
            </td>
            <td>
              <div class="stock-info">
                <span class="stock-quantity">{{ product.currentStock || product.stock || 0 }}</span>
                <span class="stock-status" :class="getStockStatusClass(product.currentStock || product.stock || 0, product.minStock)">
                  {{ getStockStatusText(product.currentStock || product.stock || 0, product.minStock) }}
                </span>
              </div>
            </td>
            <td>
              <span class="status" :class="(product.status || '').toLowerCase()">
                {{ getStatusText(product.status) }}
              </span>
            </td>
            <td>
              <span class="create-time">{{ formatDate(product.createdAt) }}</span>
            </td>
            <td>
              <div class="actions">
                <button class="btn-view" @click="viewProduct(product)">
                  <i class="fas fa-eye"></i>
                  查看
                </button>
                <button class="btn-edit" @click="editProduct(product)">
                  <i class="fas fa-edit"></i>
                  编辑
                </button>
                <button 
                  class="btn-toggle" 
                  :class="(product.status || '') === 'Active' ? 'btn-disable' : 'btn-enable'"
                  @click="toggleStatus(product)"
                >
                  <i :class="(product.status || '') === 'Active' ? 'fas fa-ban' : 'fas fa-check'"></i>
                  {{ (product.status || '') === 'Active' ? '禁用' : '启用' }}
                </button>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
      </div>
      
      <!-- 分页 -->
      <div class="pagination">
        <button :disabled="currentPage === 1" @click="currentPage--">
          <i class="fas fa-chevron-left"></i>
        </button>
        <span class="page-info">
          第 {{ currentPage }} 页，共 {{ totalPages }} 页
        </span>
        <button :disabled="currentPage === totalPages" @click="currentPage++">
          <i class="fas fa-chevron-right"></i>
        </button>
      </div>
    </div>

    <!-- 创建商品模态框 -->
    <div v-if="showCreateModal" class="modal-overlay" @click="showCreateModal = false">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>添加零售商品</h3>
          <button class="modal-close" @click="showCreateModal = false">
            <i class="fas fa-times"></i>
          </button>
        </div>
        <div class="modal-body">
          <CreateProductForm @close="showCreateModal = false" @success="handleCreateSuccess" />
        </div>
      </div>
    </div>

    <!-- 查看商品模态框 -->
    <div v-if="showViewModal" class="modal-overlay" @click="showViewModal = false">
      <div class="modal-content large" @click.stop>
        <div class="modal-header">
          <h3>商品详情</h3>
          <button class="modal-close" @click="showViewModal = false">
            <i class="fas fa-times"></i>
          </button>
        </div>
        <div class="modal-body">
          <ProductDetailView :product="selectedProduct" />
        </div>
      </div>
    </div>

    <!-- 编辑商品模态框 -->
    <div v-if="showEditModal" class="modal-overlay" @click="showEditModal = false">
      <div class="modal-content edit-modal" @click.stop>
        <div class="modal-header">
          <h3>编辑商品</h3>
          <button class="modal-close" @click="showEditModal = false">
            <i class="fas fa-times"></i>
          </button>
        </div>
        <div class="modal-body">
          <EditProductForm :product="selectedProduct" @close="showEditModal = false" @success="handleEditSuccess" />
        </div>
      </div>
    </div>

  </div>
</template>

<script>
import { ref, onMounted, computed } from 'vue'
import { apiGet } from '@/utils/api'
import CreateProductForm from './CreateForm.vue'
import ProductDetailView from './ProductDetail.vue'
import EditProductForm from './EditForm.vue'

export default {
  name: 'RetailProductsIndex',
  components: {
    CreateProductForm,
    ProductDetailView,
    EditProductForm
  },
  setup() {
    const showCreateModal = ref(false)
    const showViewModal = ref(false)
    const showEditModal = ref(false)
    const selectedProduct = ref(null)
    const currentPage = ref(1)
    const pageSize = ref(10)
    
    // 搜索表单
    const searchForm = ref({
      productName: '',
      productCode: '',
      status: '',
      stockStatus: ''
    })
    
    // 商品数据
    const products = ref([])
    const groupByProduct = ref(false)
    
    // 计算显示的商品列表（分组或原始）
    const displayProducts = computed(() => {
      if (!groupByProduct.value) {
        return products.value
      }
      
      // 按基础商品分组
      const grouped = new Map()
      products.value.forEach(product => {
        const key = product.productId || product.productid
        if (!grouped.has(key)) {
          grouped.set(key, {
            ...product,
            variants: []
          })
        }
        grouped.get(key).variants.push(product)
      })
      
      return Array.from(grouped.values())
    })
    
    const totalPages = computed(() => Math.ceil(displayProducts.value.length / pageSize.value))
    
    // 获取状态文本
    const getStatusText = (status) => {
      const statuses = {
        'Active': '启用',
        'Inactive': '禁用'
      }
      return statuses[status] || status
    }
    
    // 获取库存状态文本
    const getStockStatusText = (stock, minStock) => {
      if (stock === 0) return '缺货'
      if (stock <= minStock) return '低库存'
      return '正常'
    }
    
    // 获取库存状态样式类
    const getStockStatusClass = (stock, minStock) => {
      if (stock === 0) return 'out'
      if (stock <= minStock) return 'low'
      return 'normal'
    }
    
    // 格式化日期
    const formatDate = (date) => {
      return new Date(date).toLocaleDateString('zh-CN')
    }
    
    // 搜索商品
    const searchProducts = () => {
      console.log('搜索商品:', searchForm.value)
    }
    
    // 重置搜索
    const resetSearch = () => {
      searchForm.value = {
        productName: '',
        productCode: '',
        status: '',
        stockStatus: ''
      }
      searchProducts()
    }
    
    // 切换分组视图
    const toggleGroupView = () => {
      console.log('切换分组视图:', groupByProduct.value)
    }
    
    // 查看商品
    const viewProduct = async (product) => {
      try {
        console.log('获取商品详情:', product.id)
        const response = await apiGet(`/retail/products/${product.id}`)
        selectedProduct.value = response
        showViewModal.value = true
      } catch (error) {
        console.error('获取商品详情失败:', error)
        // 如果API失败，使用列表数据作为备用
        selectedProduct.value = product
        showViewModal.value = true
      }
    }
    
    // 编辑商品
    const editProduct = async (product) => {
      try {
        console.log('获取商品详情用于编辑:', product.id)
        const response = await apiGet(`/retail/products/${product.id}`)
        selectedProduct.value = response
        showEditModal.value = true
      } catch (error) {
        console.error('获取商品详情失败:', error)
        // 如果API失败，使用列表数据作为备用
        selectedProduct.value = product
        showEditModal.value = true
      }
    }
    
    
    // 切换状态
    const toggleStatus = async (product) => {
      try {
        const newStatus = product.status === 'Active' ? 'Inactive' : 'Active'
        const response = await fetch(`/api/retail/products/${product.id}/status?status=${newStatus}`, {
          method: 'PUT',
          headers: {
            'Authorization': `Bearer ${localStorage.getItem('token')}`
          }
        })
        
        if (response.ok) {
          console.log('商品状态更新成功')
          // 更新本地数据
          product.status = newStatus
          // 重新加载列表
          loadProducts()
        } else {
          console.error('更新商品状态失败:', response.statusText)
          alert('更新商品状态失败，请重试')
        }
      } catch (error) {
        console.error('更新商品状态失败:', error)
        alert('更新商品状态失败，请检查网络连接')
      }
    }
    
    // 创建成功回调
    const handleCreateSuccess = () => {
      showCreateModal.value = false
      loadProducts()
    }
    
    // 编辑成功回调
    const handleEditSuccess = () => {
      showEditModal.value = false
      loadProducts()
    }
    
    
    // 加载商品列表
    const loadProducts = async () => {
      try {
        const response = await fetch('/api/retail/products', {
          method: 'GET',
          headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${localStorage.getItem('token')}`
          }
        })
        
        if (response.ok) {
          const data = await response.json()
          products.value = data.content || data.products || []
        } else {
          console.error('加载商品列表失败:', response.statusText)
        }
      } catch (error) {
        console.error('加载商品列表失败:', error)
      }
    }
    
    onMounted(() => {
      loadProducts()
    })
    
    return {
      showCreateModal,
      showViewModal,
      showEditModal,
      selectedProduct,
      currentPage,
      pageSize,
      totalPages,
      searchForm,
      products,
      displayProducts,
      groupByProduct,
      toggleGroupView,
      getStatusText,
      getStockStatusText,
      getStockStatusClass,
      formatDate,
      searchProducts,
      resetSearch,
      viewProduct,
      editProduct,
      toggleStatus,
      handleCreateSuccess,
      handleEditSuccess
    }
  }
}
</script>

<style scoped>
.retail-products {
  padding: 20px;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  position: relative;
}

.retail-products::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="75" cy="75" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="50" cy="10" r="0.5" fill="rgba(255,255,255,0.1)"/><circle cx="10" cy="60" r="0.5" fill="rgba(255,255,255,0.1)"/><circle cx="90" cy="40" r="0.5" fill="rgba(255,255,255,0.1)"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
  opacity: 0.3;
  pointer-events: none;
}

.page-header {
  margin-bottom: 30px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 25px 30px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
  position: relative;
  overflow: hidden;
}

.page-header::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  animation: float 6s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(180deg); }
}

.page-header h1 {
  margin: 0 0 10px 0;
  font-size: 32px;
  color: white;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  position: relative;
  z-index: 1;
}

.header-actions {
  display: flex;
  gap: 12px;
  position: relative;
  z-index: 1;
  align-items: center;
}

.view-toggle {
  display: flex;
  align-items: center;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  color: #4a5568;
}

.toggle-label input[type="checkbox"] {
  margin: 0;
}

.toggle-text {
  font-weight: 500;
}

.btn-primary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.btn-primary:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.search-action-section {
  background: rgba(255, 255, 255, 0.95);
  padding: 25px 30px;
  border-radius: 16px;
  margin-bottom: 25px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
}

.search-action-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
}

.search-form {
  display: flex;
  gap: 20px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.form-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-item label {
  font-weight: 500;
  color: #333;
  font-size: 14px;
}

.form-item input,
.form-item select {
  padding: 12px 16px;
  border: 2px solid #e1e5e9;
  border-radius: 12px;
  font-size: 14px;
  min-width: 180px;
  background: rgba(255, 255, 255, 0.9);
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.form-item input:focus,
.form-item select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.2);
}

.form-item input:hover,
.form-item select:hover {
  border-color: #adb5bd;
  transform: translateY(-1px);
}

.form-buttons {
  display: flex;
  gap: 10px;
}

.btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
}

.btn-secondary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(240, 147, 251, 0.4);
}

.table-pagination-section {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
  margin-bottom: 25px;
}

.table-pagination-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #4facfe 0%, #00f2fe 50%, #43e97b 100%);
}

.table-container {
  overflow-x: auto;
  padding: 20px 20px 0 20px;
}

.table-container table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table-container th {
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  padding: 16px 12px;
  text-align: left;
  font-weight: 700;
  color: #374151;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid #e2e8f0;
}

.table-container td {
  padding: 16px 12px;
  border-bottom: 1px solid rgba(225, 229, 233, 0.5);
  vertical-align: middle;
}

.table-container tbody tr {
  transition: all 0.3s ease;
}

.table-container tbody tr:hover {
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
}

.product-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.product-image {
  width: 50px;
  height: 50px;
  border-radius: 6px;
  overflow: hidden;
  background: #f7fafc;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.product-name {
  font-weight: 500;
  color: #2d3748;
  font-size: 0.875rem;
}

.sku-variant {
  font-size: 0.75rem;
  color: #718096;
  font-weight: 400;
  margin-left: 4px;
}

.product-code {
  font-size: 0.75rem;
  color: #718096;
}

.product-sku {
  font-size: 0.75rem;
  color: #a0aec0;
}

.retail-price {
  font-weight: 600;
  color: #2d3748;
}

.member-price {
  font-size: 0.875rem;
  color: #43e97b;
}

.cost-price {
  font-size: 0.875rem;
  color: #718096;
}

.stock-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stock-quantity {
  font-weight: 600;
  color: #2d3748;
}

.stock-range {
  font-size: 0.875rem;
  color: #718096;
}

.status {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: inline-block;
}

.status.active {
  background: linear-gradient(135deg, #c6f6d5 0%, #9ae6b4 100%);
  color: #22543d;
  border: 1px solid rgba(34, 84, 61, 0.3);
}

.status.inactive {
  background: linear-gradient(135deg, #fed7d7 0%, #feb2b2 100%);
  color: #742a2a;
  border: 1px solid rgba(116, 42, 42, 0.3);
}

.create-time {
  font-size: 0.875rem;
  color: #718096;
}

.actions {
  display: flex;
  gap: 8px;
}

.actions button {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-view {
  background: linear-gradient(135deg, #e6fffa 0%, #b2f5ea 100%);
  color: #234e52;
  box-shadow: 0 2px 8px rgba(35, 78, 82, 0.2);
}

.btn-edit {
  background: linear-gradient(135deg, #fef5e7 0%, #fed7aa 100%);
  color: #744210;
  box-shadow: 0 2px 8px rgba(116, 66, 16, 0.2);
}

.btn-delete {
  background: linear-gradient(135deg, #fed7d7 0%, #feb2b2 100%);
  color: #742a2a;
  box-shadow: 0 2px 8px rgba(116, 42, 42, 0.2);
}

.actions button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  padding: 20px;
  background: rgba(248, 249, 250, 0.8);
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.page-info {
  color: #6b7280;
  font-size: 13px;
  font-weight: 500;
}

.pagination button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 2px solid #e5e7eb;
  background: white;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 13px;
  font-weight: 600;
}

.pagination button:hover:not(:disabled) {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: #667eea;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: white;
  border-radius: 16px;
  max-width: 600px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  border: 1px solid #e2e8f0;
}

.modal-content.large {
  max-width: 1000px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid #e2e8f0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 16px 16px 0 0;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: white;
  margin: 0;
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 600;
  color: white;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.modal-body {
  padding: 24px;
  background: #fafbfc;
}

@media (max-width: 768px) {
  .search-form {
    flex-direction: column;
    align-items: stretch;
  }
  
  .form-item input,
  .form-item select {
    min-width: auto;
  }
  
  .page-header {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }
  
  .table-container {
    overflow-x: auto;
  }
  
  .actions {
    flex-direction: column;
  }
  
  .modal-content {
    width: 95%;
    margin: 10px;
  }
}

.member-price {
  font-weight: 500;
  color: #43e97b;
}

.stock-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stock-quantity {
  font-weight: 500;
  color: #2d3748;
}

.stock-status {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

.stock-status.normal {
  background: #c6f6d5;
  color: #22543d;
}

.stock-status.low {
  background: #fef5e7;
  color: #744210;
}

.stock-status.out {
  background: #fed7d7;
  color: #742a2a;
}

.status {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
}

.status.active {
  background: #c6f6d5;
  color: #22543d;
}

.status.inactive {
  background: #fed7d7;
  color: #742a2a;
}

.create-time {
  font-size: 0.875rem;
  color: #718096;
}

.actions {
  display: flex;
  gap: 8px;
}

.actions button {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-view {
  background: #e6fffa;
  color: #234e52;
}

.btn-edit {
  background: #fef5e7;
  color: #744210;
}

.btn-stock {
  background: #bee3f8;
  color: #1a365d;
}

.btn-enable {
  background: #c6f6d5;
  color: #22543d;
}

.btn-disable {
  background: #fed7d7;
  color: #742a2a;
}

.actions button:hover {
  transform: translateY(-1px);
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 24px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.pagination button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid #e2e8f0;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.pagination button:hover:not(:disabled) {
  background: #43e97b;
  color: white;
  border-color: #43e97b;
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-info {
  font-size: 0.875rem;
  color: #4a5568;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  border-radius: 12px;
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal-content.large {
  max-width: 1000px;
}

.modal-content.edit-modal {
  max-width: 900px;
  max-height: 95vh;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px;
  border-bottom: 1px solid #e2e8f0;
}

.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #2d3748;
  margin: 0;
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: #f7fafc;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.modal-close:hover {
  background: #e2e8f0;
}

.modal-body {
  padding: 24px;
}

@media (max-width: 768px) {
  .search-form {
    grid-template-columns: 1fr;
  }
  
  .page-header {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }
  
  .products-table {
    overflow-x: auto;
  }
  
  .actions {
    flex-direction: column;
  }
}
</style>
